#ifndef _BMP_H
#define _BMP_H

#define SSP_BUSY  4
//#define BMP_START 0x01f40000
#define BMP_START 0xa3ff0000

typedef unsigned char           UINT8;
typedef signed char             INT8;
typedef unsigned short          UINT16;
typedef signed short            INT16;
typedef unsigned int            UINT32;
typedef signed int              INT32;
typedef unsigned long long      UINT64;
typedef signed long long        INT64;

typedef UINT8                   bool;
typedef UINT8                   BYTE;
typedef UINT16                  UINT;
typedef UINT16                  WORD;
typedef UINT32                  DWORD;
typedef UINT32                  LONG;

typedef struct tagBITMAPFILEHEADER {    // bmfh                                                                                     
        UINT    bfType;
        DWORD   bfSize;
        UINT    bfReserved1;
        UINT    bfReserved2;
        DWORD   bfOffBits;
} __attribute__((packed)) BITMAPFILEHEADER;

typedef struct tagBITMAPINFOHEADER {    /* bmih */
        DWORD   biSize;
        LONG    biWidth;
        LONG    biHeight;
        WORD    biPlanes;
        WORD    biBitCount;
        DWORD   biCompression;
        DWORD   biSizeImage;
        LONG    biXPelsPerMeter;
        LONG    biYPelsPerMeter;
        DWORD   biClrUsed;
        DWORD   biClrImportant;
} __attribute__((packed)) BITMAPINFOHEADER;

typedef struct tagRGBQUAD {     /* rgbq */
        BYTE    rgbBlue;
        BYTE    rgbGreen;
        BYTE    rgbRed;
        BYTE    rgbReserved;
} __attribute__((packed)) RGBQUAD;

typedef struct tagBITMAPFILE {
        BITMAPFILEHEADER bmfh;
        BITMAPINFOHEADER bmih;
        RGBQUAD          aColors[16];
        BYTE             aBitmapBits[];
} __attribute__((packed)) BITMAPFILE;

unsigned short aColors[] = {
        0, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0
};


typedef struct LCDFrameDescriptorS {
    UINT32 FDADR;
    UINT32 FSADR;
    UINT32 FIDR;
    UINT32 LDCMD;
} LCDFrameDescriptorT;


typedef struct FrameHeaderS {
    int size;                 // Total size of the frame in bytes.
    int horizPixel;
    int vertPixel;
    int extraLines;
    LCDFrameDescriptorT DmaDescriptor;
} FrameHeaderT;

typedef struct FrameS
{
    FrameHeaderT header;
    UINT16 buffer[1];
} FrameT;


/* Panel geometry for LCD setup */
typedef struct DM_LcdDefinition_S {
    int panelWidth;
    int panelHeight;
    int extraLines;

    char panelType;
    char dualPanel;
    char activeDisplay;
    char colorDepth;

    //******* LCCR1 ******** 
    char horizSyncPW;
    char horizELW;
    char horizBLW;
    //char reserved1;

    //******* LCCR2 ******** 
    char vertSyncPW;
    char vertEFW;
    char vertBFW;
    //char reserved2;
  
    //******* LCCR3 ******** 
    int  pixelClkDiv;
    char frameSyncPol;
    char horizSyncPol;
    char clockPol;
    char outputEnaPol;

    short acBiasCount;
    //short reserved3;
} DM_LcdDefinition_T;


// initial values for the Samsung 320X240 display
static DM_LcdDefinition_T Samsung_LTS222Q1 = {          
    240,              // panelWidth (LCCR1)
    320,              // panelHeight
    0,                // extraLines
          
          
    1,                //Panel_TypeLcd,         // panelType
    0,                // dualPanel (FALSE)
    1,                // activeDisplay (TRUE)
    16,               // colorDepth (bits per pixel)
                            
    //******* LCCR1 ******** 
    1,                // horizSyncPW (horizontal sync pulse width)
    3,                // horizELW (horizontal end of line pixel clock wait count)
    3,                // horizBLW (horizontal beginning of line pixel clock wait count)
                            
    //******* LCCR2 ******** 
    1,                // vertSyncPW (vertical sync pulse width)
    1,                // vertEFW (vertical end of frame line clock wait count)
    0,               // vertBFW (vertical beginning of frame clock wait count)
                            
    //******* LCCR3 ******** 
    9,                // pixelClkDiv
    0,                // frameSyncPol   samsung:active low
    1,                // horizSyncPol    samsung:active low
    0,                // clockPol     "0": rising edge "1":falling edge
    0,                // outputEnaPol
          
    0                 // acBiasCount
};


#endif
